﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;

namespace Homework2
{
    public partial class Form1 : Form
    {
        private int Num;
        private int Pin;
        public ATM Atm { get; }
        private Form2 form2;
        public Form1()
        {
            InitializeComponent();
            label3.ForeColor = Color.Red;
            Atm = new ATM();

            textBox1.Text = "123456";
            textBox2.Text = "123456";

        }
        public void E_Show()
        {
            textBox1.Text = "";
            textBox2.Text = "";
            Show();
        }
        private void Connect()
        {
            if (int.TryParse(textBox1.Text, out Num) && int.TryParse(textBox2.Text, out Pin))
            {
                if (Atm.Connect(Num.ToString(), Pin.ToString()))
                {
                    Hide();
                    form2 = new Form2(Atm);
                    form2.exit += E_Show;
                    form2.Show();
                    
                    //Show();
                    //MessageBox.Show("Connect Success");
                }
                else
                {
                    label3.Text = "The account number or password is incorrect";
                    //MessageBox.Show("The account number or password is incorrect");
                }
            }
            else
            {
                label3.Text = "Please enter a valid time and number of questions.";
                //MessageBox.Show("Please enter a valid time and number of questions.");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Connect();
        }
    }
}
